#include "form_cachedata.h"
#include "ui_form_cachedata.h"
#include "serialportusr.h"


extern SerialPortUsr * g_serial_port_pt;

Form_CacheData::Form_CacheData(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Form_CacheData)
{
    ui->setupUi(this);
}

Form_CacheData::~Form_CacheData()
{
    delete ui;
}

void Form_CacheData::on_pushButton_back_clicked()
{
    close();
}

void Form_CacheData::on_pushButton_save_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 F1 00 02 00 30 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_channel_clicked()
{
    QString temp_qstr;
    int temp_i;
    char temp_c[5];

    temp_qstr="EE B1 11 00 03 00 0C 11 ";
    temp_i = ui->lineEdit_channel->text().toUInt();
    //提取百位
    itoa(temp_i/100+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i%100;
    //提取十位
    itoa(temp_i/10+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i %10;
    //提取个位
    itoa(temp_i+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_time_m_clicked()
{
    QString temp_qstr;
    int temp_i;
    char temp_c[5];

    temp_qstr="EE B1 11 00 03 00 0E 11 ";
    temp_i = ui->lineEdit_time_m->text().toUInt();
    //提取百位
    itoa(temp_i/100+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i%100;
    //提取十位
    itoa(temp_i/10+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i %10;
    //提取个位
    itoa(temp_i+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_time_s_clicked()
{
    QString temp_qstr;
    int temp_i;
    char temp_c[5];

    temp_qstr="EE B1 11 00 03 00 0F 11 ";
    temp_i = ui->lineEdit_time_s->text().toUInt();
    //提取百位
    itoa(temp_i/100+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i%100;
    //提取十位
    itoa(temp_i/10+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    temp_i = temp_i %10;
    //提取个位
    itoa(temp_i+0x30,temp_c,16);
    temp_qstr.append(temp_c).append(" ");
    //帧尾
    temp_qstr.append("00 FF FC FF FF");
    qDebug()<<temp_qstr;
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray(temp_qstr);
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_nextProgramWash_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 31 00 01 00 34 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_previousProgramWash_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 322 00 01 00 33 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_1_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 21 00 01 00 3D 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_row_2_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 22 00 01 00 3E 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_row_3_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 23 00 01 00 3F 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_4_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 24 00 01 00 40 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_5_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 25 00 01 00 41 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_6_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 26 00 01 00 42 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_7_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 27 00 01 00 43 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_row_8_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 28 00 01 00 44 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);
}

void Form_CacheData::on_pushButton_row_9_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 29 00 01 00 45 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_10_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 2A 00 01 00 46 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_11_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 2B 00 01 00 47 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}

void Form_CacheData::on_pushButton_row_12_clicked()
{
    QByteArray temp_arr = g_serial_port_pt->hexStringToByteArray("EE A1 2C 00 01 00 48 30 00 FF FC FF FF");
    g_serial_port_pt->sendData(temp_arr);

}
